#include "devicemodel.h"

DeviceModel::DeviceModel()
{

}

Any DeviceModel::sqlSelect(char *sql)
{

    Device *ch;

    int row;
    int col;
    char *errmsg;
    char **datares;
     int count=1;
    qDebug()<<sql;
    int res=sqlite3_get_table(this->psqlite3,sql,&datares,&row,&col,&errmsg);
    qDebug()<<"row="<<row;
    if(res==SQLITE_OK)
    {
        for(int i=1;i<row+1;i++)
        {
            ch=new Device();
            for(int j=col*i;j<col*(i+1);j++)
            {

                if(count==5)
                {
                    ch->setVideoPath(datares[j]);
                }
                else if(count==6)
                {
                    qDebug()<<datares[j];
                    ch->setImagePath(datares[j]);
                    count=1;
                    break;
                }
                else if(count==2)
                {
                    ch->setDeviceName(datares[j]);
                }
                count++;
            }

        }
    }
    else
    {
        qDebug()<<"读取数据失败，错误码为"<<sqlite3_errcode(psqlite3);
        qDebug()<<"操作失败";
    }

    sqlite3_free_table(datares); // 释放查询结果的内存
    return Any(ch);
}
